home *** CD-ROM | disk | FTP | other *** search
- /* Faster version of calculate deltas which precomputes the luminance for the image
- ** before calculating deltas.
- ** Note: Both GWorlds (src any depth, dst 8-bit grayscale)
- ** must be allocated when this routine is called.
- */
-
- #include "DemoRoutines.h"
-
- void FastCalculateDeltas( GWorldPtr src, GWorldPtr dst )
- {
- PixMapHandle srcPixMap, dstPixMap;
- short srcRowBytes, dstRowBytes;
- long *srcBaseAddr, *dstBaseAddr, *dstAddr;
- unsigned char *srcAddr1;
- char mmuMode;
- short row, column;
- unsigned char lum1,lum2;
- unsigned long dstLong;
- short width, height;
- GDHandle oldGD;
- GWorldPtr oldGW;
-
- srcPixMap = GetGWorldPixMap ( src );
- dstPixMap = GetGWorldPixMap ( dst );
-
- if ( LockPixels ( srcPixMap ) && LockPixels( dstPixMap) )
- { /* lock the pixmaps */
- GetGWorld(&oldGW,&oldGD);
- SetGWorld(dst,nil);
- CopyBits( (BitMap*)*srcPixMap, (BitMap*)*dstPixMap, &(**srcPixMap).bounds, &(**dstPixMap).bounds, srcCopy, 0L );
- SetGWorld( oldGW, oldGD );
-
- srcBaseAddr = (long *) GetPixBaseAddr ( srcPixMap ); /* get the address of the pixmap */
- srcRowBytes = (**srcPixMap).rowBytes & 0x7fff; /* get the row increment */
- dstBaseAddr = (long *) GetPixBaseAddr ( dstPixMap ); /* get the address of the pixmap */
- dstRowBytes = (**dstPixMap).rowBytes & 0x7fff; /* get the row increment */
- width = (**srcPixMap).bounds.right-(**srcPixMap).bounds.left;
- height = (**srcPixMap).bounds.bottom-(**srcPixMap).bounds.top;
-
- mmuMode = true32b;
- SwapMMUMode ( &mmuMode ); /* set the MMU to 32-bit mode */
- for ( row = 0; row < height; row++ )
- {
- srcAddr1 = (unsigned char *)dstBaseAddr;
- dstAddr = dstBaseAddr;
- lum1 = *srcAddr1++; /* get luminance of src pixel */
- for ( column = 0; column < ((width-1)/4); column++ )
- {
- /*
- ** Do a long in the destination (4 pixels)
- ** This is o.k. since memory blocks are always long word aligned.
- ** Thus, we will never write over the right hand edge.
- */
- dstLong = 0;
- lum2 = *srcAddr1++;
- dstLong = (unsigned char)((0x100 + lum1 - lum2)>>1);
- dstLong = dstLong << 8;
- lum1 = *srcAddr1++;
- dstLong |= (unsigned char)((0x100 + lum2 - lum1)>>1);
- dstLong = dstLong<<8;
- lum2 = *srcAddr1++;
- dstLong |= (unsigned char)((0x100 + lum1 - lum2)>>1);
- dstLong = dstLong << 8;
- lum1 = *srcAddr1++;
- dstLong |= (unsigned char)((0x100 + lum2 - lum1)>>1);
- *dstAddr++ = dstLong;
- }
-
- srcBaseAddr = (long *) ( (char *) srcBaseAddr + srcRowBytes ); /* go to the next row */
- dstBaseAddr = (long *) ( (char *) dstBaseAddr + dstRowBytes ); /* go to the next row */
- }
- SwapMMUMode ( &mmuMode ); /* restore the previous MMU mode */
- UnlockPixels ( srcPixMap ); /* unlock the pixmap */
- UnlockPixels ( dstPixMap ); /* unlock the pixmap */
- }
- }
-